#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class UF
{
public:
    UF(int N)
    {
        size = new int[N + 1];
        fill(size, size + N + 1, 0);
        parent = new int[N + 1];
        fill(parent, parent + N + 1, -1);
    }
    int findPar(int x)
    {
        if (parent[x] == -1)
            return x;
        int par = findPar(parent[x]);
        parent[x] = par;
        return par;
    }
    void Union(int x, int y)
    {
        int parx = findPar(x), pary = findPar(y);
        if (parx == pary)
            return;
        if (size[parx] < size[pary])
        {
            parent[parx] = pary;
            size[pary] += size[parx];
        }
        else
        {
            parent[pary] = parx;
            size[parx] += size[pary];
        }
    }
    bool isOneClass(int x, int y)
    {
        return findPar(x) == findPar(y);
    }

private:
    int *size, *parent;
};
int main()
{
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    UF uf(N);
    for (int i = 1, z, x, y; i <= M; ++i)
    {
        cin >> z >> x >> y;
        if (z == 1)
        {
            uf.Union(x, y);
        }
        else if (z == 2)
        {
            cout << (uf.isOneClass(x, y) ? "Y" : "N") << endl;
        }
    }
    return 0;
}